

#include "HandlerThread.h"

HandlerThread::HandlerThread() : HandlerThread(new Handler(this)) {

}

HandlerThread::HandlerThread(Handler *pHandler) {
  _pHandler = pHandler;
}

HandlerThread::~HandlerThread() noexcept {
  DELETE_PTR(_pHandler)
}

void HandlerThread::running(void *pPtr) {
  _pHandler->loop();
}

void HandlerThread::stopThread() {
  Thread::stopThread();
  sendMessage(MsgID_Release);
}

bool HandlerThread::sendMessage(int32_t what) {
  if (_pHandler) {
    return _pHandler->sendMessage(what);
  }

  return false;
}

bool HandlerThread::sendMessage(Message *pMsg) {
  if (_pHandler) {
    return _pHandler->sendMessage(pMsg);
  }

  return false;
}